package project.dbaccesslayer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.TreeMap;

public class Table_SO_Questions_Raw_html {

	public static String get_page(Connection conn, Long id) throws SQLException {
		PreparedStatement s = conn
				.prepareStatement("SELECT html FROM SO_Questions_Raw_html WHERE Question_id = ? ");
		s.setLong(1, id);
		ResultSet r = s.executeQuery();
		r.next();
		String p = r.getString("html");
		return p;
	}

	public static void saveQuestionRawHtml(Connection conn, long id, String html)
			throws SQLException {
		PreparedStatement s = conn
				.prepareStatement("INSERT INTO SO_Questions_Raw_html"
						+ "(Question_id, html) VALUES(?,?)");
		s.setLong(1, id);
		s.setString(2, html);

		s.executeUpdate();
	}

	public static Map<Long, String> getQuestionsToParse(Connection conn)
			throws SQLException {
		PreparedStatement s = conn.prepareStatement("CALL GetQuestionsToParse(); ");
		ResultSet r = s.executeQuery();
		Map<Long, String> map = new TreeMap<Long, String>();
		while (r.next()) {
			map.put(r.getLong("Question_Id"), r.getString("html"));
		}
		return map;
	}
}
